package com.yimingkeji.mybatis.mapper;

import com.yimingkeji.mybatis.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @Describe:
 * @Auther: zhenlong.yang
 * @Date: 2018/12/14 13:17
 */
public interface UserMapper {

    @Select("select * from user")
    @Results({
            @Result(property = "phoneNumber", column = "phone_number"),
            @Result(property = "createTime", column = "create_time", javaType = Date.class)
    })
    List<User> findAll();

    @Select("select * from user where id = #{id}")
    User findOne(int id);

    @Insert("insert into user(name, age, phone_number, available, create_time) values (#{name}, #{age}, #{phoneNumber}, #{available}, #{createTime})")
    int add(User user);

    @Update("update user set name=#{name} where id = #{id}")
    int update(User user);

    @Delete("delete from user where id = #{id}")
    int delete(int id);
}
